﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Personalplaner.Modules.Dienstplan.Print
{
    [ToolboxItem(false)]
	public partial class AbteilungPrintSelect : UserControl, Gencode.Gengui.Forms.IDialogControl, Gencode.Gengui.Forms.IReturnValueDialog
	{
		Dictionary<string, int> m_abteilungen;
		AbteilungPrintRetVal retVal;

		public AbteilungPrintSelect(int planid)
		{
			InitializeComponent();
			int schemaid = Gencode.PrsCommon.Data.Plan.PlanData.GetPlanSchemaID(planid);
			DataView dv = Gencode.PrsCommon.Data.Plan.PlanData.GetAbteilungenInSchema(schemaid);

			m_abteilungen = new Dictionary<string, int>();
			m_abteilungen.Add("Alle", 0);
			comboAbteilung.Items.Add("Alle");
			foreach (DataRowView row in dv)
			{
				m_abteilungen.Add(row["name"].ToString(), int.Parse(row["abteilungid"].ToString()));
				comboAbteilung.Items.Add(row["name"].ToString());
			}
			comboAbteilung.SelectedIndex = 0;

			txtCopies.Text = "1";
		}

		#region IDialogControl Members

		public bool OKClicked()
		{
			retVal = new AbteilungPrintRetVal();
			retVal.AbteilungID = m_abteilungen[comboAbteilung.Text];
			retVal.UseDefaultPrinter = checkBox1.Checked;
			retVal.Copies = int.Parse(txtCopies.Text);
            retVal.Preview = checkPreview.Checked;

			return true;
		}

		public bool CancleClicked()
		{
			return true;
		}

		#endregion

		#region IReturnValueDialog Members

		public object ReturnValue
		{
			get { return retVal; }
		}

		#endregion
	}

	public class AbteilungPrintRetVal
	{
		public int AbteilungID
		{
			get;
			set;
		}

		public bool UseDefaultPrinter
		{
			get;
			set;
		}

		public int Copies
		{
			get;
			set;
		}

        public bool Preview
        {
            get;
            set;
        }
	}
}
